Kodo update

Brightcells 7 lat temu
rodzic
commit
2181a06f23
5 zmienionych plików z 115 dodań i 5 usunięć
  1. 20 1
      api/encrypt_views.py
  2. 3 3
      api/mch_views.py
  3. 48 0
      mch/migrations/0002_auto_20180104_0414.py
  4. 43 1
      mch/models.py
  5. 1 0
      requirements.txt

+ 20 - 1
api/encrypt_views.py

@@ -2,13 +2,15 @@
2 2
 
3 3
 from __future__ import division
4 4
 
5
+import json
5 6
 import random
6 7
 
8
+from django_response import response
7 9
 from logit import logit
8 10
 
11
+from mch.models import BrandInfo, ModelImageInfo, ModelInfo
9 12
 from utils.algorithm.b64 import b64_decrypt, b64_encrypt
10 13
 from utils.algorithm.rsalg import rsa_decrypt, rsa_encrypt
11
-from utils.error.response_utils import response
12 14
 
13 15
 
14 16
 # CIPHER_ALGORITHM = ('B64', 'RSA')
@@ -51,6 +53,23 @@ def decrypt(request):
51 53
     else:
52 54
         plaintext = ciphertext
53 55
 
56
+    infos = json.loads(plaintext)
57
+
58
+    Brand = infos.get('Brand', '')
59
+    Model = infos.get('Model', '')
60
+
61
+    try:
62
+        logo_url = BrandInfo.objects.get(brand_name=Brand).brand_logo_url
63
+    except BrandInfo.DoesNotExist:
64
+        logo_url = ''
65
+
66
+    try:
67
+        model_imgs = ModelInfo.objects.get(model_name=Model).images
68
+    except ModelInfo.DoesNotExist:
69
+        model_imgs = []
70
+
54 71
     return response(200, data={
55 72
         'plaintext': plaintext,
73
+        'logo_url': logo_url,
74
+        'model_imgs': model_imgs,
56 75
     })

+ 3 - 3
api/mch_views.py

@@ -7,7 +7,7 @@ from utils.error.response_utils import response
7 7
 
8 8
 
9 9
 def brands_list(request):
10
-    brands = BrandInfo.objects.filter(status=True)
10
+    brands = BrandInfo.objects.filter(status=True).order_by('position')
11 11
     brands = [brand.data for brand in brands]
12 12
 
13 13
     return response(200, data={
@@ -16,7 +16,7 @@ def brands_list(request):
16 16
 
17 17
 
18 18
 def models_list(request):
19
-    models = ModelInfo.objects.filter(status=True)
19
+    models = ModelInfo.objects.filter(status=True).order_by('position')
20 20
     models = [model.data for model in models]
21 21
 
22 22
     return response(200, data={
@@ -25,7 +25,7 @@ def models_list(request):
25 25
 
26 26
 
27 27
 def distributors_list(request):
28
-    distributors = DistributorInfo.objects.filter(status=True)
28
+    distributors = DistributorInfo.objects.filter(status=True).order_by('position')
29 29
     distributors = [distributor.data for distributor in distributors]
30 30
 
31 31
     return response(200, data={

+ 48 - 0
mch/migrations/0002_auto_20180104_0414.py

@@ -0,0 +1,48 @@
1
+# -*- coding: utf-8 -*-
2
+# Generated by Django 1.11.3 on 2018-01-03 20:14
3
+from __future__ import unicode_literals
4
+
5
+from django.db import migrations, models
6
+import models_ext.fileext
7
+
8
+
9
+class Migration(migrations.Migration):
10
+
11
+    dependencies = [
12
+        ('mch', '0001_initial'),
13
+    ]
14
+
15
+    operations = [
16
+        migrations.CreateModel(
17
+            name='ModelImageInfo',
18
+            fields=[
19
+                ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
20
+                ('status', models.BooleanField(db_index=True, default=True, help_text='Status', verbose_name='status')),
21
+                ('created_at', models.DateTimeField(auto_now_add=True, help_text='Create Time', verbose_name='created_at')),
22
+                ('updated_at', models.DateTimeField(auto_now=True, help_text='Update Time', verbose_name='updated_at')),
23
+                ('model_id', models.CharField(blank=True, db_index=True, help_text='\u578b\u53f7\u552f\u4e00\u6807\u8bc6', max_length=32, null=True, verbose_name='model_id')),
24
+                ('image', models.ImageField(blank=True, help_text='\u56fe\u7247', null=True, upload_to=models_ext.fileext.upload_path, verbose_name='image')),
25
+                ('url', models.TextField(blank=True, help_text='\u94fe\u63a5', max_length=255, null=True, verbose_name='url')),
26
+                ('position', models.IntegerField(default=1, help_text='\u6392\u5e8f', verbose_name='position')),
27
+            ],
28
+            options={
29
+                'verbose_name': '\u578b\u53f7\u56fe\u7247\u4fe1\u606f',
30
+                'verbose_name_plural': '\u578b\u53f7\u56fe\u7247\u4fe1\u606f',
31
+            },
32
+        ),
33
+        migrations.AddField(
34
+            model_name='brandinfo',
35
+            name='brand_logo',
36
+            field=models.ImageField(blank=True, help_text='\u54c1\u724c\u5546\u6807', null=True, upload_to=models_ext.fileext.upload_path, verbose_name='brand_logo'),
37
+        ),
38
+        migrations.AddField(
39
+            model_name='distributorinfo',
40
+            name='brand_id',
41
+            field=models.CharField(blank=True, db_index=True, help_text='\u54c1\u724c\u552f\u4e00\u6807\u8bc6', max_length=32, null=True, verbose_name='brand_id'),
42
+        ),
43
+        migrations.AddField(
44
+            model_name='modelinfo',
45
+            name='brand_id',
46
+            field=models.CharField(blank=True, db_index=True, help_text='\u54c1\u724c\u552f\u4e00\u6807\u8bc6', max_length=32, null=True, verbose_name='brand_id'),
47
+        ),
48
+    ]

+ 43 - 1
mch/models.py

@@ -2,7 +2,7 @@
2 2
 
3 3
 from django.db import models
4 4
 from django.utils.translation import ugettext_lazy as _
5
-from models_ext import BaseModelMixin
5
+from models_ext import BaseModelMixin, upload_file_url, upload_path
6 6
 from shortuuidfield import ShortUUIDField
7 7
 
8 8
 
@@ -11,6 +11,8 @@ class BrandInfo(BaseModelMixin):
11 11
     brand_name = models.CharField(_(u'brand_name'), max_length=255, blank=True, null=True, help_text=u'品牌名称')
12 12
     brand_descr = models.TextField(_(u'brand_descr'), max_length=255, blank=True, null=True, help_text=u'品牌描述')
13 13
 
14
+    brand_logo = models.ImageField(_(u'brand_logo'), upload_to=upload_path, blank=True, null=True, help_text=u'品牌商标')
15
+
14 16
     position = models.IntegerField(_(u'position'), default=1, help_text=u'排序')
15 17
 
16 18
     class Meta:
@@ -21,6 +23,10 @@ class BrandInfo(BaseModelMixin):
21 23
         return unicode(self.pk)
22 24
 
23 25
     @property
26
+    def brand_logo_url(self):
27
+        return upload_file_url(self.brand_logo)
28
+
29
+    @property
24 30
     def data(self):
25 31
         return {
26 32
             'brand_id': self.brand_id,
@@ -30,6 +36,8 @@ class BrandInfo(BaseModelMixin):
30 36
 
31 37
 
32 38
 class ModelInfo(BaseModelMixin):
39
+    brand_id = models.CharField(_(u'brand_id'), max_length=32, blank=True, null=True, help_text=u'品牌唯一标识', db_index=True)
40
+
33 41
     model_id = ShortUUIDField(_(u'model_id'), max_length=32, help_text=u'型号唯一标识', db_index=True, unique=True)
34 42
     model_name = models.CharField(_(u'model_name'), max_length=255, blank=True, null=True, help_text=u'型号名称')
35 43
     model_descr = models.TextField(_(u'model_descr'), max_length=255, blank=True, null=True, help_text=u'型号描述')
@@ -51,8 +59,42 @@ class ModelInfo(BaseModelMixin):
51 59
             'model_descr': self.model_descr,
52 60
         }
53 61
 
62
+    @property
63
+    def images(self):
64
+        imgs = ModelImageInfo.objects.filter(model_id=self.model_id, status=True)
65
+        return [img.data for img in imgs]
66
+
67
+
68
+class ModelImageInfo(BaseModelMixin):
69
+    model_id = models.CharField(_(u'model_id'), max_length=32, blank=True, null=True, help_text=u'型号唯一标识', db_index=True)
70
+
71
+    image = models.ImageField(_(u'image'), upload_to=upload_path, blank=True, null=True, help_text=u'图片')
72
+    url = models.TextField(_(u'url'), max_length=255, blank=True, null=True, help_text=u'链接')
73
+
74
+    position = models.IntegerField(_(u'position'), default=1, help_text=u'排序')
75
+
76
+    class Meta:
77
+        verbose_name = _(u'型号图片信息')
78
+        verbose_name_plural = _(u'型号图片信息')
79
+
80
+    def __unicode__(self):
81
+        return unicode(self.pk)
82
+
83
+    @property
84
+    def image_url(self):
85
+        return upload_file_url(self.image)
86
+
87
+    @property
88
+    def data(self):
89
+        return {
90
+            'image_url': self.image_url,
91
+            'url': self.url,
92
+        }
93
+
54 94
 
55 95
 class DistributorInfo(BaseModelMixin):
96
+    brand_id = models.CharField(_(u'brand_id'), max_length=32, blank=True, null=True, help_text=u'品牌唯一标识', db_index=True)
97
+
56 98
     distributor_id = ShortUUIDField(_(u'distributor_id'), max_length=32, help_text=u'经销商唯一标识', db_index=True, unique=True)
57 99
     distributor_name = models.CharField(_(u'distributor_name'), max_length=255, blank=True, null=True, help_text=u'经销商名称')
58 100
     distributor_descr = models.TextField(_(u'distributor_descr'), max_length=255, blank=True, null=True, help_text=u'经销商描述')

+ 1 - 0
requirements.txt

@@ -18,6 +18,7 @@ django-mobi==0.1.7
18 18
 django-models-ext==1.0.5
19 19
 django-multidomain==1.1.4
20 20
 django-paginator2==1.0.3
21
+django-response==1.0.0
21 22
 django-rlog==1.0.7
22 23
 django-shortuuidfield==0.1.3
23 24
 django-six==1.0.4